package labuladong.第四章;

public class CanJump {
    public static void main(String[] args) {
        int[] nums = {2, 3, 1, 1, 4};
        int[] nums2 = {3, 2, 1, 0, 4};
        System.out.println(canJump01(nums));
        System.out.println(canJump01(nums2));
    }

    public static boolean canJump01(int[] nums) {
        int n = nums.length;
        int farthest = 0;
        for(int i=0; i<n; i++) {
            farthest = Math.max(farthest, i+nums[i]);
            if(farthest <= i) return false;
        }
        return farthest >= n-1;
    }
}
